/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */

var isSymmetric = function (root) {
    if (!root) {
        return true
    }
    return fn(root.left, root.right)
    function fn(left, right) {
        if (!left && !right) {
            return true
        } else if (left && right && left.val === right.val) {
            return fn(left.left, right.right) && fn(left.right, right.left)
        } else {
            return false
        }
    }
};